package com.heima.wemedia.feign;

import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannerlDto;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.SensitiveDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author HNCheng
 * @version 1.0
 * @since 2023/8/3 15:56
 */
@RestController
public class WemediaClient implements IWemediaClient {

    @Autowired
    private WmChannelService wmChannelService;

    @Autowired
    private WmNewsService wmNewsService;

    @Autowired
    private WmSensitiveService wmSensitiveService;

    @Autowired
    private WmGreenScanService wmGreenScanService;

    @Autowired
    private WmAutoScanService wmAutoScanService;

    @Autowired
    private WmUserService wmUserService;

    /**
     * 删除频道
     */
    @GetMapping("/api/v1/channel/del/{id}")
    @Override
    public ResponseResult delete(Integer id) {
        return wmChannelService.delete(id);
    }

    /**
     * 查询文章列表
     *
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/api/v1/news/list_vo")
    @Override
    public ResponseResult listVo(NewsAuthDto newsAuthDto) {
        return wmNewsService.listVo(newsAuthDto);
    }

    /**
     * 查询文章详情
     *
     * @param id
     * @return
     */
    @GetMapping("/api/v1/news/one_vo/{id}")
    @Override
    public ResponseResult wmNewsInfo(Integer id) {
        return wmNewsService.wmNewsInfo(id);
    }

    /**
     * 频道名称模糊分页查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/channel/list")
    @Override
    public ResponseResult findByNamePage(ChannerlDto dto) {
        return wmChannelService.findByNamePage(dto);
    }

    /**
     * 审核失败
     *
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/api/v1/news/auth_fail")
    @Override
    public ResponseResult authFail(NewsAuthDto newsAuthDto) {
        return wmNewsService.updateStatus(newsAuthDto);
    }

    /**
     * 审核成功
     *
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/api/v1/news/auth_pass")
    @Override
    public ResponseResult authPass(NewsAuthDto newsAuthDto) {
        return wmNewsService.updateStatus(newsAuthDto);
    }

    /**
     * 新增频道
     *
     * @param wmChannel
     * @return
     */
    @PostMapping("/api/v1/channel/save")
    @Override
    public ResponseResult save(WmChannel wmChannel) {
        return wmChannelService.saveChannel(wmChannel);
    }

    /**
     * 修改频道
     *
     * @param wmChannel
     * @return
     */
    @PostMapping("/api/v1/channel/update")
    @Override
    public ResponseResult update(WmChannel wmChannel) {
        return wmChannelService.updateChannel(wmChannel);
    }

    /**
     * 敏感词分页查询
     *
     * @param sensitiveDto
     * @return
     */
    @PostMapping("/api/v1/sensitive/list")
    @Override
    public ResponseResult listSensitive(SensitiveDto sensitiveDto) {
        return wmSensitiveService.list(sensitiveDto);
    }

    /**
     * 敏感词删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/api/v1/sensitive/del/{id}")
    @Override
    public ResponseResult deleteSensitive(Integer id) {
        return wmSensitiveService.delete(id);
    }

    /**
     * 敏感词新增
     *
     * @param wmSensitive
     * @return
     */
    @PostMapping("/api/v1/sensitive/save")
    @Override
    public ResponseResult insertSensitive(WmSensitive wmSensitive) {
        return wmSensitiveService.insert(wmSensitive);
    }

    /**
     * 敏感词修改
     *
     * @param wmSensitive
     * @return
     */
    @PostMapping("/api/v1/sensitive/update")
    @Override
    public ResponseResult updateSensitive(WmSensitive wmSensitive) {
        return wmSensitiveService.update(wmSensitive);
    }

    /**
     * 审核文本
     *
     * @param text
     * @return
     */
    @Override
    @PostMapping("/api/v1/news/scan_text")
    public Map<String, String> scanText(String text) {
        return wmAutoScanService.scanCommentText(text);
    }

    /**
     * 存入数据到wmUser表中
     *
     * @param wmUser
     */
    @Override
    @PostMapping("api/v1/wmuser/set")
    public void setWmUser(@RequestBody WmUser wmUser) {
        wmUserService.save(wmUser);
    }

    /**
     * 通过authorId获取wmUser数据
     *
     * @param authorId
     * @return
     */
    @Override
    @GetMapping("/api/v1/wmuser/obtain/{authorId}")
    public WmUser obtainWmUser(@PathVariable("authorId") Integer authorId) {
        return wmUserService.obtainWmUser(authorId);
    }

    /**
     * 查询数据库中channel列表
     *
     * @return
     */
    @Override
    @GetMapping("/api/vi/channel/select")
    public List<WmChannel> selectChannel() {
        return wmChannelService.selectChannel();
    }
}
